tools/xenstore: libxenstore: fix threading bug which cause xend startup hang
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 10 Sep 2010 18:06:33 +0000 (19:06 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Fri, 10 Sep 2010 18:06:33 +0000 (19:06 +0100)
commite9ee80826066e8592b55d9692a536dc20cf6ee5f
treebc2212f75d9e4f456d65367ef488601b0956ca20
parentc528148dd32190ab302e602384a63d4519eaba86
tools/xenstore: libxenstore: fix threading bug which cause xend startup hang

If a multithreaded caller creates a thread which calls xs_read_watch,
before it has set any watches with xs_watch, the thread in
xs_read_watch will enter read_message and sit reading the xenstored fd
without the appropriate locks held.  Other threads can then
concurrently read the xenstored fd, which naturally does not work very
well.

Symptoms of this bug which I have been able to reproduce include
failure of xend startup to finish, due to a deadlock; results could
also include reading corrupted data from xenstore.

In this patch we arrange for xs_read_watch to always rely on the
reader thread created by xs_watch.  If no watches have been set, then
xs_read_watch will block until one has been.  If the library is
compiled non-threaded xs_read_watch unconditionally does the reading
in the current thread.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/xenstore/xs.c